package com.topisv.tms.service.stock.outstorage;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.topisv.tms.entity.stock.oustorage.OutstorageBill;
import com.topisv.tms.entity.stock.oustorage.OutstorageBox;
import com.topisv.tms.entity.stock.oustorage.OutstorageBoxItem;
import com.topisv.tms.repository.stock.outstorage.OutstorageBillDao;
import com.topisv.tms.repository.stock.outstorage.OutstorageBoxDao;
import com.topisv.tms.repository.stock.outstorage.OutstorageBoxItemDao;

/**
 * 出库箱明细_service
 * @author ch
 *
 */
@Component
@Transactional(readOnly = true)
public class OutstorageBoxItemService {
	
	@Autowired
	private OutstorageBoxItemDao outstorageBoxItemDao;
	
	@Autowired
	private OutstorageBillDao outstorageBillDao;
	
	@Autowired
	private OutstorageBoxDao outstorageBoxDao;

	/**
	 * 添加出库箱明细
	 * @param boxCode
	 * @param sku
	 * @param num
	 */
	public Long addBoxItem(String boxCode, String sku, Integer num) {
		OutstorageBox box=this.outstorageBoxDao.loadByBoxCode(boxCode);
		OutstorageBill bill = outstorageBillDao.loadByBillCode(box.getBillCode());
		OutstorageBoxItem item=new OutstorageBoxItem();
		item.setBill(bill);
		item.setBoxCode(boxCode);
		item.setSku(sku);
		item.setNum(num);
		this.outstorageBoxItemDao.save(item);
		
		return item.getId();
		
	}

	/**
	 * 删除商品
	 * @param itemId
	 */
	@Transactional(readOnly = false)
	public void delGoods(Long itemId) {
		this.outstorageBoxItemDao.delete(itemId);
	}

}
